<?php
/**
 * Created by PhpStorm.
 * User: mac
 * Date: 2019-03-02
 * Time: 00:08
 */

//woole_async_readfile最大可读取4M的文件，受限于SW_AIO_MAX_FILESIZE宏
swoole_async_readfile(__DIR__ . '/1.txt', function ($filename, $fileContent) {
    echo 'readfile - filename is ' . $filename . PHP_EOL;
    echo 'readfile - content is ' . $fileContent . PHP_EOL;
});

//它是分段读取，可以用于读取超大文件。每次只读$size个字节，不会占用太多内存。
swoole_async_read(__DIR__ . '/1.txt', function ($filename, $fileContent) {
    echo 'read - filename is ' . $filename . PHP_EOL;
    echo 'read - content is ' . $fileContent . PHP_EOL;
}, 8192, 0);